(function(){

	var clientObjects = {};

	phnq =
	{
		createObject: function()
		{
			var numArgs = arguments.length;
			if(numArgs==0)
				return null;
			
			var key = arguments[0];
			
			var clientObject = clientObjects[key];
			if(clientObject)
				return clientObject;
			
			var callback = null;
		
			var args = [];
			for(var i=0; i<numArgs; i++)
			{
				var arg = arguments[i];
				if(typeof(arg)=="function")
					callback = arg;
				else
					args.push(arg);
			}

			return phnq.io.exec("data", {args:args.join(",")}, callback);
		},
		
		encodeUrl: function(url)
		{
			var winUri = new phnq.util.URI(location.href);
			var l = winUri.params.l || "en";
			var uri = new phnq.util.URI(url, {l:l});
			return uri.toString();
		},
		
		print: function()
		{
			console.log.apply(null, arguments);
		},
		
		addDependency: function(type)
		{
			// TBD...
			// phnq.print("addDependency: "+type);
		}
	};

	phnq.client =
	{
		browser:
		{
			version: (navigator.userAgent.toLowerCase().match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
		    IE:     !!(window.attachEvent && !window.opera),
		    Opera:  !!window.opera,
		    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
		    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1
		},
		
		setGlobal: function(name, val)
		{
			var o = window;
			var comps = name.split(".");
			var len = comps.length;
			for(var i=0; i<len-1; i++)
			{
				var comp = comps[i];
				o = o[comp] = {};
			}
			o[comps[len-1]] = val;
		}
	};
	
	var httpParams = {};
	var comps = location.search.split(/[&?]/);
	var compsLen = comps.length;
	for(var i=0; i<compsLen; i++)
	{
		var comp = comps[i];
		if(comp)
		{
			var nvp = comp.split("=");
			httpParams[nvp[0]] = nvp[1];
		}
	}
	
	clientObjects.http =
	{
		params:httpParams
	};

})();
